/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;
import java.sql.*;

public class ConnectDatabase 
{
    private static Connection con = null;
    private static String url = "jdbc:sqlserver://";
    private static String serverName= "HOANGCHUONG-PC";
    private static String portNumber = "1433";
    private static String databaseName= "SuperMarket";

     

     public ConnectDatabase()
     {}
     
     public static String getConnectionUrl()
     {
         return url + serverName + ":" + portNumber + "; databaseName=" + databaseName + "; username=sa; password=123456";
     }

     public static Connection getConnection() throws Exception
     {
          try
          {
               Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
               con = DriverManager.getConnection(getConnectionUrl());
          }
          catch(Exception e)
          {
              con = null;
              throw new Exception(e.getMessage()); 
          }
          return con;
      }

     public static void closeConnection()
     {
          try
          {
               if(con!=null)
                    con.close();
               con=null;
          }
          catch(Exception e)
          {
               e.printStackTrace();
          }
     }

    
}

